package org.wanda.pv.service.business.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.FieldFilter;
import org.nutz.dao.util.Daos;
import org.springframework.stereotype.Service;
import org.wanda.pv.model.business.Topic;
import org.wanda.pv.model.hy.HyUserInfo;
import org.wanda.pv.model.user.SysUser;
import org.wanda.pv.service.BaseServiceImpl;
import org.wanda.pv.service.business.TopicService;

/**
 * @author lxy
 * @date 2018/11/24 10:17
 */
@Service
public class TopicServiceImpl  extends BaseServiceImpl<Topic> implements TopicService {
    private final Log log = LogFactory.getLog(this.getClass());

    public TopicServiceImpl(Dao dao) {
        super(dao);
    }

    @Override
    public Topic addRevertByMark(Long markId, String content,  Long  userId ,Long pointId) throws Exception {
        try{
            Topic topic = new Topic();
            topic.setType(1);
            topic.setMarkId(markId);
            topic.setContent(content);
            topic.setHyUserInfoId(userId);
            HyUserInfo user = dao().fetch(HyUserInfo.class, Cnd.where("id","=",userId));
            topic.setHyUserInfo(user);
            topic = dao().insert(topic);
            topic.setHyUserInfo(user);
            dao().insert("wd_re_mark_topic", Chain.make("mark_id",markId).add("topic_id",topic.getId()));
            return topic;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
